/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "ITEM")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Item.findAll", query = "SELECT i FROM Item i"),
    @NamedQuery(name = "Item.findByIdItem", query = "SELECT i FROM Item i WHERE i.itemPK.idItem = :idItem"),
    @NamedQuery(name = "Item.findByIdProduct", query = "SELECT i FROM Item i WHERE i.itemPK.idProduct = :idProduct"),
    @NamedQuery(name = "Item.findByIdBranchenterprise", query = "SELECT i FROM Item i WHERE i.itemPK.idBranchenterprise = :idBranchenterprise"),
    @NamedQuery(name = "Item.findByIdEnterprise", query = "SELECT i FROM Item i WHERE i.itemPK.idEnterprise = :idEnterprise"),
    @NamedQuery(name = "Item.findByDamage", query = "SELECT i FROM Item i WHERE i.damage = :damage"),
    @NamedQuery(name = "Item.findByPromotion", query = "SELECT i FROM Item i WHERE i.promotion = :promotion"),
    @NamedQuery(name = "Item.findByExpirationdate", query = "SELECT i FROM Item i WHERE i.expirationdate = :expirationdate")})
public class Item implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ItemPK itemPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "DAMAGE")
    private BigInteger damage;
    @Basic(optional = false)
    @NotNull
    @Column(name = "PROMOTION")
    private BigInteger promotion;
    @Basic(optional = false)
    @NotNull
    @Column(name = "EXPIRATIONDATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date expirationdate;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "item", fetch = FetchType.LAZY)
    private List<ItemStatus> itemStatusList;
    @JoinColumn(name = "WAREHOUSE", referencedColumnName = "ID_WAREHOUSE")
    @ManyToOne(fetch = FetchType.LAZY)
    private Warehouse warehouse;
    @JoinColumns({
        @JoinColumn(name = "ID_PRODUCT", referencedColumnName = "ID_PRODUCT", insertable = false, updatable = false),
        @JoinColumn(name = "ID_BRANCHENTERPRISE", referencedColumnName = "ID_BRANCHENTERPRISE", insertable = false, updatable = false),
        @JoinColumn(name = "ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE", insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Product product;
    @JoinColumn(name = "ID_LOCATION", referencedColumnName = "ID_LOCATION")
    @ManyToOne(fetch = FetchType.LAZY)
    private Location idLocation;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "item", fetch = FetchType.LAZY)
    private ItemCampaign itemCampaign;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "item", fetch = FetchType.LAZY)
    private OrderItem orderItem;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "item", fetch = FetchType.LAZY)
    private ItemCatalog itemCatalog;

    public Item() {
    }

    public Item(ItemPK itemPK) {
        this.itemPK = itemPK;
    }

    public Item(ItemPK itemPK, BigInteger damage, BigInteger promotion, Date expirationdate) {
        this.itemPK = itemPK;
        this.damage = damage;
        this.promotion = promotion;
        this.expirationdate = expirationdate;
    }

    public Item(BigInteger idItem, BigInteger idProduct, BigInteger idBranchenterprise, BigInteger idEnterprise) {
        this.itemPK = new ItemPK(idItem, idProduct, idBranchenterprise, idEnterprise);
    }

    public ItemPK getItemPK() {
        return itemPK;
    }

    public void setItemPK(ItemPK itemPK) {
        this.itemPK = itemPK;
    }

    public BigInteger getDamage() {
        return damage;
    }

    public void setDamage(BigInteger damage) {
        this.damage = damage;
    }

    public BigInteger getPromotion() {
        return promotion;
    }

    public void setPromotion(BigInteger promotion) {
        this.promotion = promotion;
    }

    public Date getExpirationdate() {
        return expirationdate;
    }

    public void setExpirationdate(Date expirationdate) {
        this.expirationdate = expirationdate;
    }

    @XmlTransient
    public List<ItemStatus> getItemStatusList() {
        return itemStatusList;
    }

    public void setItemStatusList(List<ItemStatus> itemStatusList) {
        this.itemStatusList = itemStatusList;
    }

    public Warehouse getWarehouse() {
        return warehouse;
    }

    public void setWarehouse(Warehouse warehouse) {
        this.warehouse = warehouse;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Location getIdLocation() {
        return idLocation;
    }

    public void setIdLocation(Location idLocation) {
        this.idLocation = idLocation;
    }

    public ItemCampaign getItemCampaign() {
        return itemCampaign;
    }

    public void setItemCampaign(ItemCampaign itemCampaign) {
        this.itemCampaign = itemCampaign;
    }

    public OrderItem getOrderItem() {
        return orderItem;
    }

    public void setOrderItem(OrderItem orderItem) {
        this.orderItem = orderItem;
    }

    public ItemCatalog getItemCatalog() {
        return itemCatalog;
    }

    public void setItemCatalog(ItemCatalog itemCatalog) {
        this.itemCatalog = itemCatalog;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (itemPK != null ? itemPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Item)) {
            return false;
        }
        Item other = (Item) object;
        if ((this.itemPK == null && other.itemPK != null) || (this.itemPK != null && !this.itemPK.equals(other.itemPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Item[ itemPK=" + itemPK + " ]";
    }
    
}
